<cfif Not IsDefined("session.id")>
		<cflocation url = "/ecada/" addToken = "no">
</cfif>
	
<cfif IsDefined("session.experiment")>
	<cfset experiment = session.experiment>
<cfelse>
	<cflocation url="/ecada/" addToken="No" >
</cfif>


<cfif IsDefined("form.submit")>

<cfelse>

	
	<cfinclude template= "/ecada/header.cfm">
<cfoutput>
	<style type="text/css">
								
									.stimImage
									{
										display: inline-block;
										margin-left: 10px;
										width: 75px;
										height: 75px;
									}
									
									.Questions
									{
										display: inline-block;
									}
									
									.Question-Row
									{
										
										width: 100%;
										height: 25px;
									}
									
									.Question-Row form
									{
										margin: 0;
										width: 100%;
									}
									
									.Question-Num
									{
										display: inline-block;
										font-weight: bold;
									}
									
									.Question-Text
									{
										display: inline-block;
										width: 370px;
									}
									
									.Question-Actions
									{
										display: inline-block;
										Width: 30px;
									}
								
									.button
									{
										width: 50px;
									}
									
								</style>
		<script type="text/javascript">
			$(document).ready(function(){
			//this function is defined in progressbar.cfm and is included in the header
				setProgressText("Stimuli &amp; Question Pairer");
				setProgress(5);
			});
		</script>
	</cfoutput>
	<cfquery datasource="exp" name="conditions">
		SELECT *
		FROM conditions
		WHERE expid = #experiment.id#
		ORDER BY id
	</cfquery>
	
	<cfloop query="conditions">
		<cfoutput>

				<fieldset>
					<legend>
							Condition: #HTMLEditFormat(Title)#
					</legend>
					
					<cfquery datasource="exp" name="stimuli">
						SELECT *
						FROM stim
						WHERE CondID = #id#
						ORDER BY Title Asc
					</cfquery>
					
					<cfloop query="stimuli">	
					
						<cfquery datasource="exp" name="ImageDetails">
							SELECT *
							FROM filestore
							WHERE id = #FileID#
						</cfquery>
						
						<fieldset>
						
							<legend>
								#HTMLEditFormat(Title)#
							</legend>
							
							<div>	
							
								
								
								<div class="stimImage">
									<img style="width: 75px; height: 75px; margin: 0;" src="/ecada/files/#ImageDetails.filepath#/#ImageDetails.filename#" width="75px" height="75px" alt="#ImageDetails.filename#" />
								</div>
								
								<cfquery datasource="exp" name="stimQuestions">
									SELECT *
									FROM StimQuestions sq
									WHERE sq.StimID = #id#
								</cfquery>
								
								<cfset i = 1>
								
								<div class="Questions">
								
									<cfloop query="stimQuestions">
										
										<cfquery datasource="exp" name="Q">
											SELECT *
											FROM question q
											WHERE q.id = #QuestionID#
											AND expid = #experiment.id#
										</cfquery>
										
										<div class="Question-Row">
											<div class="Question-Num">
												Q#i#
												<cfset i += 1>
											</div>
											<div class="Question-Text">
												#Q.Question#
											</div>
											<div class="Question-Actions">
												<form method="post" action="unset/">
													<input type="hidden" value="#StimID#" name="StimID">
													<input type="hidden" value="#QuestionID#" name="QuestionID">
													<button class="ui-state-default ui-corner-all button" title="Unset" type="submit" value="Unset">
														<div>
															<div style="display: inline-block; margin: 3px;line-height: 16px;"><b>Unset</b></div>
														</div>
													</button>
												</form>
											</div>
										</div>
									</cfloop>
									<cfquery datasource="exp" name="questions">
										SELECT q.*, qt.type
										FROM question q, qestiontype qt
										WHERE expid = #experiment.id#
										AND q.typeID = qt.id
										AND q.id NOT IN (SELECT QuestionID FROM StimQuestions WHERE StimId = #id#)
										ORDER BY q.id
									</cfquery>
									<cfif questions.recordcount neq 0>
										<div class="Question-Row">
											<form method="post" action="Set/">
												<div class="Question-Num">
													Q#i#
												</div>
												<div class="Question-Text">
													<select style="width: 370px;" name="Question">
														<cfloop query="questions">
															<option value="#id#">
																#question#
															</option>
														</cfloop>
													</select>
												</div>
												<div class="Question-Actions">
													<input type="hidden" name="StimID" value="#id#">
													<button class="ui-state-default ui-corner-all button" title="Set" type="submit" value="Set">
														<div>
															<div style="display: inline-block; margin: 3px;line-height: 16px;"><b>Set</b></div>
														</div>
													</button>
												</div>
											</form>
										</div>
									</cfif>
								</div>
							</div>
						</fieldset>
					</cfloop>
			</fieldset>
		</cfoutput>
	</cfloop>
	<cfoutput>
	<div>
		<div style="width: 100%;">
			<div style="width: 10%; float: left;">
				<form method="post" action="./../Step-4">
					<button class="ui-state-default ui-corner-all" title="Back" type="submit" value="Back">
						<div>
							<div style="display: inline-block; margin: 3px;line-height: 16px;"><b>Back</b></div>
						</div>
					</button>
				</form>
			</div >
			<div style="width: 50%; float:left;">
				<form method="post" action="./../Step-6">
					<button class="ui-state-default ui-corner-all" title="Next" type="submit" value="Next">
							<div>
								<div style="display: inline-block; margin: 3px;line-height: 16px;"><b>Next</b></div>
							</div>
						</button>
				</form>
			</div>
		</div>
	</div>
	</cfoutput>
	<cfinclude template= "/ecada/footer.cfm">

</cfif>



